//加载公共样式
require('../../assets/css/index.less')

//服务器地址
const API = 'http://fitness.h5.itsource.cn:3701'

let dom = require('../../utils/dom')
const request = require('../../utils/request')

//字体图标
require('../../assets/fonts/iconfont.css')
//加载自己的样式
require('./courseTrain.less')

window.onload = () => {
    dom.Tmenu('courseTrain')

    //获取课程列表
    function getCourseList() {
        request.get('/api/train/courseList').then(res => {
            console.log(res);
            let { errno, data } = res.data
            if (errno == 0) {
                // console.log(data);
                data.map((v, i) => {
                    if (i == 0) {
                        Course('#newCourse', v)
                    } else {
                        Course('#course', v)
                    }
                })
            }
        })
    }
    getCourseList()

    function Course(type, data) {
        document.querySelector(type).innerHTML += `
        <a href="course.html?id=${data.courseId}">
        <div class="courseId">
        <img src=${API + data.imgurl} alt="">
            <div class="couse-details">
                <h3 class="font14">${data.name}</h3>
                <p class="font12">${data.desc}</p>
            </div>
        </div>
        </a>
        `
    }
}